package com.junxian.springboot03.juc;

import java.util.concurrent.CountDownLatch;

/**
 * 同步工具类：减法计时器
 */
public class CountDownLatchTest {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(20);

        //模拟教室放学关门,30个学生走完了，才关门
        for (int i = 1; i <= 20; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "走了。");
                countDownLatch.countDown();
            }, "学号为" +i+"的同学").start();
        }

        countDownLatch.await();
        System.out.println("全部学生走完，关门大吉！");

    }

}
